package com.lefeng.cockpit.admin;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 启动SpringBoot
 */
@EnableAsync
@EnableScheduling
@ServletComponentScan
@EnableTransactionManagement
@SpringBootApplication(scanBasePackages = {"com.lefeng.cockpit.admin", "com.lefeng.cockpit.datax", "com.lefeng.cockpit.resource"})
@Slf4j
public class Cockpit {
    private static final Logger LOGGER = LoggerFactory.getLogger(Cockpit.class);

    public static void main(String[] args) {
        try {
//            SpringApplication sa = new SpringApplication(DiDiSecurity.class);
//            sa.run(args);

            ApplicationContext context = SpringApplication.run(Cockpit.class, args);

            // 获取所有 Bean 的名称
            String[] beanNames = context.getBeanDefinitionNames();

            // 打印每个 Bean 的名称和实例
            for (String beanName : beanNames) {

                Object bean = context.getBean(beanName);
                if (bean.toString().startsWith("com.lefeng")) {
                    log.info("{}: {}", beanName, bean);
                }

            }
            LOGGER.info("== Cockpit started ==");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
